package view.manager;

import java.awt.EventQueue;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.JInternalFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import base.NumberGeneration;
import controller.DateChooser;
import dao.ClassinformationDao;
import dao.MajorDao;
import dao.ManagerDao;
import dao.StudentDao;
import model.Classinformation;
import model.Major;
import model.Manager;
import model.Student;
import util.StringUtil;

import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.JRadioButton;
import javax.swing.JComboBox;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ButtonGroup;

public class StudentEditInterfrm extends JInternalFrame {
	private JTextField textFieldName;
	private JTable tableStudent;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	private JTextField textField_6;
	private JComboBox comboBoxPolitical;
	private JComboBox comboBoxMajor;
	private JComboBox comboBoxClass;

	private String sex = "男";
	private String mid = null;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					StudentEditInterfrm frame = new StudentEditInterfrm();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public StudentEditInterfrm() {
		setClosable(true);
		setIconifiable(true);
		setTitle("学生管理");
		setBounds(100, 100, 1201, 739);

		JLabel lblNewLabel = new JLabel("学生姓名：");

		textFieldName = new JTextField();
		textFieldName.setColumns(10);

		JButton btnNewButton = new JButton("查询");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ArrayList<Student> arrayList = new ArrayList<Student>();
				ArrayList<Student> List = new ArrayList<Student>();
				arrayList = StudentDao.select();
				for (Student student : arrayList) {
					if (student.getStu_name().contains(textFieldName.getText())) {
						List.add(student);
					}
				}
				filltable(List);
			}
		});
		btnNewButton.setIcon(new ImageIcon(StudentEditInterfrm.class.getResource("/images/select.png")));

		JScrollPane scrollPane = new JScrollPane();

		JPanel panel = new JPanel();
		panel.setBorder(
				new TitledBorder(null, "\u8868\u5355\u64CD\u4F5C", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
						.addGroup(groupLayout
								.createParallelGroup(Alignment.LEADING)
								.addGroup(
										groupLayout.createSequentialGroup().addGap(58).addComponent(lblNewLabel)
												.addPreferredGap(ComponentPlacement.RELATED)
												.addComponent(textFieldName, GroupLayout.PREFERRED_SIZE, 152,
														GroupLayout.PREFERRED_SIZE)
												.addGap(18).addComponent(btnNewButton))
								.addGroup(groupLayout.createSequentialGroup().addGap(21)
										.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
												.addComponent(panel, GroupLayout.DEFAULT_SIZE, 1146, Short.MAX_VALUE)
												.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 1146,
														Short.MAX_VALUE))))
						.addContainerGap(18, GroupLayout.PREFERRED_SIZE)));
		groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup().addGap(18)
						.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel)
								.addComponent(textFieldName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
										GroupLayout.PREFERRED_SIZE)
								.addComponent(btnNewButton))
						.addGap(18)
						.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 201, GroupLayout.PREFERRED_SIZE)
						.addGap(18).addComponent(panel, GroupLayout.PREFERRED_SIZE, 368, GroupLayout.PREFERRED_SIZE)
						.addContainerGap(57, Short.MAX_VALUE)));

		JLabel lblNewLabel_1 = new JLabel("学号：");

		JLabel lblNewLabel_2 = new JLabel("姓名：");

		textField = new JTextField();
		textField.setEditable(false);
		textField.setColumns(10);

		textField_1 = new JTextField();
		textField_1.setColumns(10);

		JLabel lblNewLabel_3 = new JLabel("性别：");

		JRadioButton rdbtnNewRadioButton = new JRadioButton("男");
		rdbtnNewRadioButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				sex = "男";
			}
		});
		buttonGroup.add(rdbtnNewRadioButton);

		JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("女");
		rdbtnNewRadioButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				sex = "女";
			}
		});
		buttonGroup.add(rdbtnNewRadioButton_1);

		JLabel lblNewLabel_4 = new JLabel("出生日期：");

		JPanel panelBirthday = new JPanel();
		DateChooser dateChooser = new DateChooser();
		panelBirthday.add(dateChooser);

		JLabel lblNewLabel_5 = new JLabel("身份证号：");

		textField_2 = new JTextField();
		textField_2.setColumns(10);

		JLabel lblNewLabel_6 = new JLabel("电话：");

		textField_3 = new JTextField();
		textField_3.setColumns(10);

		JLabel lblNewLabel_7 = new JLabel("籍贯：");

		textField_4 = new JTextField();
		textField_4.setColumns(10);

		JLabel lblNewLabel_8 = new JLabel("邮箱：");

		textField_5 = new JTextField();
		textField_5.setColumns(10);

		JLabel lblNewLabel_9 = new JLabel("民族：");

		textField_6 = new JTextField();
		textField_6.setColumns(10);

		JLabel lblNewLabel_10 = new JLabel("政治面貌：");

		comboBoxPolitical = new JComboBox();

		JLabel lblNewLabel_11 = new JLabel("所在系：");

		comboBoxMajor = new JComboBox();
		comboBoxMajor.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (StringUtil.isEmpty(mid)) {
					if (comboBoxMajor.getSelectedItem() instanceof Major) {
						comboBoxClass.removeAllItems();
						fillClassType((Major) comboBoxMajor.getSelectedItem());
					}
				}else {
					comboBoxClass.removeAllItems();
					fillClassType(mid);
					mid = null;
				}
			}
		});

		JButton btnNewButton_1 = new JButton("修改");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (StringUtil.isEmpty(textField.getText())) {
					JOptionPane.showMessageDialog(null, "请选择需要修改的数据", "提示", JOptionPane.ERROR_MESSAGE);
					return;
				}

				//数据校验
				if (StringUtil.isEmpty(textField_1.getText())) {
					JOptionPane.showMessageDialog(null, "请输入学生姓名", "提示", JOptionPane.ERROR_MESSAGE);
					return;
				}
				if (StringUtil.checkLenth(textField_1.getText(),5)) {
					JOptionPane.showMessageDialog(null, "请输入长度小于5的学生姓名", "提示", JOptionPane.ERROR_MESSAGE);
					return;
				}
				if (!StringUtil.isEmpty(textField_2.getText()) && !StringUtil.isIDCard(textField_2.getText())) {
					JOptionPane.showMessageDialog(null, "请输入正确的身份证号", "提示", JOptionPane.ERROR_MESSAGE);
					textField_2.requestFocus();
					textField_2.selectAll();
					return;
				}
				if (!StringUtil.isEmpty(textField_3.getText()) && !StringUtil.isMobile(textField_3.getText())) {
					JOptionPane.showMessageDialog(null, "请输入正确的电话", "提示", JOptionPane.ERROR_MESSAGE);
					textField_3.requestFocus();
					textField_3.selectAll();
					return;
				}
				if (!StringUtil.isEmpty(textField_5.getText()) && !StringUtil.isEmail(textField_5.getText())) {
					JOptionPane.showMessageDialog(null, "请输入正确的邮箱", "提示", JOptionPane.ERROR_MESSAGE);
					textField_5.requestFocus();
					textField_5.selectAll();
					return;
				}
				if (StringUtil.checkLenth(textField_4.getText(),3)) {
					JOptionPane.showMessageDialog(null, "请输入长度小于5的户籍信息", "提示", JOptionPane.ERROR_MESSAGE);
					textField_4.requestFocus();
					textField_4.selectAll();
					return;
				}
				if (StringUtil.checkLenth(textField_6.getText(),3)) {
					JOptionPane.showMessageDialog(null, "请输入长度小于5的民族信息", "提示", JOptionPane.ERROR_MESSAGE);
					textField_6.requestFocus();
					textField_6.selectAll();
					return;
				}
				Student student = StudentDao.getStudent(textField.getText());

				student.setStu_name(textField_1.getText());
				student.setStu_sex(sex);
				student.setStu_birthday(dateChooser.getSelectDate());
				student.setStu_sfz(textField_2.getText());
				student.setStu_tel(textField_3.getText());
				student.setStu_province(textField_4.getText());
				student.setStu_email(textField_5.getText());
				student.setNation(textField_6.getText());
				student.setPolitical(comboBoxPolitical.getSelectedItem().toString());
				if (comboBoxMajor.getSelectedItem() instanceof Major) {
					Major major = (Major) comboBoxMajor.getSelectedItem();
					student.setM_id(major.getM_id());
				}
				if (comboBoxClass.getSelectedItem() instanceof Classinformation) {
					Classinformation classinformation = (Classinformation) comboBoxClass.getSelectedItem();
					student.setCla_id(classinformation.getCla_id());
				}
				if (StudentDao.updata(student) > 0) {
					JOptionPane.showMessageDialog(null, "修改成功", "提示", JOptionPane.INFORMATION_MESSAGE);
					filltable(StudentDao.select());
					return;
				}
				JOptionPane.showMessageDialog(null, "修改失败", "提示", JOptionPane.ERROR_MESSAGE);
			}
		});
		btnNewButton_1.setIcon(new ImageIcon(StudentEditInterfrm.class.getResource("/images/updata.png")));

		JButton btnNewButton_2 = new JButton("删除");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (StringUtil.isEmpty(textField.getText())) {
					JOptionPane.showMessageDialog(null, "请选择需要删除的数据", "提示", JOptionPane.ERROR_MESSAGE);
					return;
				}
				int res = JOptionPane.showConfirmDialog(null, "是否确定删除");
				if (res == 0) {
					if (StudentDao.delete(textField.getText()) > 0) {
						JOptionPane.showMessageDialog(null, "删除成功", "提示", JOptionPane.INFORMATION_MESSAGE);
						textField.setText("");
						textField_1.setText("");
						textField_2.setText("");
						textField_3.setText("");
						textField_4.setText("");
						textField_5.setText("");
						textField_6.setText("");
						comboBoxMajor.removeAllItems();
						comboBoxPolitical.removeAllItems();
						dateChooser.setSelectDate();
						rdbtnNewRadioButton_1.setSelected(false);
						rdbtnNewRadioButton.setSelected(false);
						filltable(StudentDao.select());
						return;
					}
					JOptionPane.showMessageDialog(null, "删除失败", "提示", JOptionPane.ERROR_MESSAGE);
				}
			}
		});
		btnNewButton_2.setIcon(new ImageIcon(StudentEditInterfrm.class.getResource("/images/删 除 .png")));

		comboBoxClass = new JComboBox();

		JLabel lblNewLabel_12 = new JLabel("所在班级：");
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_panel.createSequentialGroup().addContainerGap(340, Short.MAX_VALUE)
						.addComponent(btnNewButton_1).addGap(162).addComponent(btnNewButton_2).addGap(470))
				.addGroup(gl_panel.createSequentialGroup().addGap(133).addGroup(gl_panel
						.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_panel.createSequentialGroup().addComponent(lblNewLabel_2)
								.addPreferredGap(ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
								.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, 127, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_panel.createSequentialGroup().addComponent(lblNewLabel_1)
								.addPreferredGap(ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
								.addComponent(textField, GroupLayout.PREFERRED_SIZE, 126, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_panel.createSequentialGroup()
								.addGroup(gl_panel.createParallelGroup(Alignment.LEADING).addComponent(lblNewLabel_3)
										.addComponent(lblNewLabel_4))
								.addPreferredGap(ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
								.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
										.addComponent(panelBirthday, GroupLayout.PREFERRED_SIZE, 124,
												GroupLayout.PREFERRED_SIZE)
										.addGroup(gl_panel.createSequentialGroup().addComponent(rdbtnNewRadioButton)
												.addGap(18).addComponent(rdbtnNewRadioButton_1)))))
						.addGap(185)
						.addGroup(gl_panel.createParallelGroup(Alignment.LEADING).addComponent(lblNewLabel_5)
								.addComponent(lblNewLabel_6).addComponent(lblNewLabel_7).addComponent(lblNewLabel_8)
								.addComponent(lblNewLabel_9))
						.addGap(6)
						.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
								.addGroup(gl_panel.createSequentialGroup()
										.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
												.addComponent(textField_5, Alignment.LEADING, GroupLayout.DEFAULT_SIZE,
														136, Short.MAX_VALUE)
												.addComponent(textField_6, GroupLayout.DEFAULT_SIZE, 136,
														Short.MAX_VALUE))
										.addGap(406))
								.addGroup(gl_panel.createSequentialGroup()
										.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING, false)
												.addComponent(textField_4, Alignment.LEADING)
												.addComponent(textField_2, Alignment.LEADING).addComponent(textField_3,
														Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 137,
														Short.MAX_VALUE))
										.addPreferredGap(ComponentPlacement.RELATED, 151, Short.MAX_VALUE)
										.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
												.addComponent(lblNewLabel_11).addComponent(lblNewLabel_12)
												.addComponent(lblNewLabel_10))
										.addGap(25)
										.addGroup(gl_panel.createParallelGroup(Alignment.LEADING, false)
												.addComponent(comboBoxMajor, 0, 130, Short.MAX_VALUE)
												.addComponent(comboBoxPolitical, 0, GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE)
												.addComponent(comboBoxClass, 0, GroupLayout.DEFAULT_SIZE,
														Short.MAX_VALUE))
										.addGap(45)))));
		gl_panel.setVerticalGroup(gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup().addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel.createSequentialGroup().addContainerGap()
								.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_10)
										.addComponent(comboBoxPolitical, GroupLayout.PREFERRED_SIZE,
												GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
						.addGroup(gl_panel.createSequentialGroup().addGap(11)
								.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
										.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE)
										.addComponent(lblNewLabel_1).addComponent(lblNewLabel_5)
										.addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE))))
						.addGroup(gl_panel.createParallelGroup(Alignment.LEADING).addGroup(gl_panel
								.createSequentialGroup().addGap(17)
								.addGroup(gl_panel.createParallelGroup(Alignment.LEADING).addGroup(gl_panel
										.createSequentialGroup()
										.addGroup(gl_panel.createParallelGroup(Alignment.LEADING).addGroup(gl_panel
												.createSequentialGroup().addGap(1)
												.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
														.addComponent(lblNewLabel_11).addComponent(lblNewLabel_6)
														.addComponent(textField_3, GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
												.addComponent(lblNewLabel_2))
										.addGap(18)
										.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
												.addComponent(rdbtnNewRadioButton).addComponent(lblNewLabel_3)
												.addComponent(rdbtnNewRadioButton_1).addComponent(lblNewLabel_7)
												.addComponent(textField_4, GroupLayout.PREFERRED_SIZE,
														GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
										.addComponent(
												textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
												GroupLayout.PREFERRED_SIZE))
								.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
										.addGroup(
												gl_panel.createSequentialGroup().addGap(26).addComponent(panelBirthday,
														GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE))
										.addGroup(
												gl_panel.createSequentialGroup().addGap(34).addComponent(lblNewLabel_4))
										.addGroup(gl_panel.createSequentialGroup().addGap(18)
												.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
														.addComponent(lblNewLabel_8).addComponent(textField_5,
																GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE)))))
								.addGroup(gl_panel.createSequentialGroup().addGap(16)
										.addComponent(comboBoxMajor, GroupLayout.PREFERRED_SIZE,
												GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
										.addGap(18)
										.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
												.addComponent(comboBoxClass, GroupLayout.PREFERRED_SIZE,
														GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
												.addComponent(lblNewLabel_12))))
						.addGap(10)
						.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_9)
								.addComponent(textField_6, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
										GroupLayout.PREFERRED_SIZE))
						.addPreferredGap(ComponentPlacement.RELATED, 74, Short.MAX_VALUE)
						.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE).addComponent(btnNewButton_2)
								.addComponent(btnNewButton_1))
						.addGap(37)));
		panel.setLayout(gl_panel);

		tableStudent = new JTable();
		tableStudent.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				/**
				 * b表格点击事件
				 */
				comboBoxMajor.removeAllItems();
				comboBoxPolitical.removeAllItems();
				comboBoxClass.removeAllItems();
				int row = tableStudent.getSelectedRow();
				Student student = StudentDao.select(tableStudent.getValueAt(row, 0).toString());
				textField.setText(student.getStu_id());
				textField_1.setText(student.getStu_name());
				textField_2.setText(student.getStu_sfz());
				textField_3.setText(student.getStu_tel());
				textField_4.setText(student.getStu_province());
				textField_5.setText(student.getStu_email());
				textField_6.setText(student.getNation());
				mid = String.valueOf(tableStudent.getValueAt(row, 12));
				fillMajorType(student.getM_id());
//				fillClassType(String.valueOf(tableStudent.getValueAt(row, 12)));
				dateChooser.setSelectDate(String.valueOf(tableStudent.getValueAt(row, 3)));
				fillPoliticalType(student.getPolitical());
				if ("女".equals(String.valueOf(tableStudent.getValueAt(row, 2)))) {
					rdbtnNewRadioButton_1.setSelected(true);
				} else if ("男".equals(String.valueOf(tableStudent.getValueAt(row, 2)))) {
					rdbtnNewRadioButton.setSelected(true);
				}
			}
		});
		tableStudent.setModel(new DefaultTableModel(
				new Object[][] { { null, null, null, null, null, null, null, null, null, null, null, null, null }, },
				new String[] { "\u5B66\u53F7", "\u59D3\u540D", "\u6027\u522B", "\u51FA\u751F\u65E5\u671F",
						"\u8EAB\u4EFD\u8BC1\u53F7", "\u7535\u8BDD", "\u7C4D\u8D2F", "\u90AE\u7BB1", "\u6C11\u65CF",
						"\u653F\u6CBB\u9762\u8C8C", "\u6240\u5728\u7CFB", "\u5165\u5B66\u5E74\u4EFD",
						"\u6240\u5728\u73ED\u7EA7" }) {
			boolean[] columnEditables = new boolean[] { false, false, false, false, false, false, false, false, false,
					false, false, false, false };

			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		tableStudent.getColumnModel().getColumn(2).setPreferredWidth(34);
		tableStudent.getColumnModel().getColumn(4).setPreferredWidth(100);
		tableStudent.getColumnModel().getColumn(6).setPreferredWidth(45);
		tableStudent.getColumnModel().getColumn(8).setPreferredWidth(45);
		scrollPane.setViewportView(tableStudent);
		getContentPane().setLayout(groupLayout);

		filltable(StudentDao.select());
	}

	private void filltable(ArrayList<Student> arrayList) {
		Major major;
		DefaultTableModel dtm = (DefaultTableModel) tableStudent.getModel();
		dtm.setRowCount(0);
		for (Student student : arrayList) {
			Vector v = new Vector();
			v.add(student.getStu_id());
			v.add(student.getStu_name());
			v.add(student.getStu_sex());
			v.add(student.getStu_birthday());
			v.add(student.getStu_sfz());
			v.add(student.getStu_tel());
			v.add(student.getStu_province());
			v.add(student.getStu_email());
			v.add(student.getNation());
			v.add(student.getPolitical());
			major = MajorDao.select(student.getM_id());
			v.add(major.getM_name());
			v.add(student.getEnrollmentYear());
			v.add(student.getCla_id());
			dtm.addRow(v);
		}
	}

	String[] politicalArr = { "", "中共党员", "中共预备党员", "共青团员", "民革党员", "民盟盟员", "民建会员", "民进会员", "农工党党员", "致公党党员", "九三学社社员",
			"台盟盟员", "无党派人士", "群众" };
	private final ButtonGroup buttonGroup = new ButtonGroup();

	/**
	 * 初始化下拉框 * 中共党员、中共预备党员、共青团员、民革党员、民盟盟员、民建会员、 民进会员、农工党党员、致公党党员
	 * 、九三学社社员、台盟盟员、无党派人士、群众
	 */
	private void fillPoliticalType() {
		for (String string : politicalArr) {
			comboBoxPolitical.addItem(string);
		}
	}

	private void fillPoliticalType(String political) {
		for (String string : politicalArr) {
			if (string.equals(political)) {
				comboBoxPolitical.addItem(string);
			}
		}
		for (String string : politicalArr) {
			if (!string.equals(political)) {
				comboBoxPolitical.addItem(string);
			}
		}
	}

	/**
	 * 初始化下拉框
	 */
	private void fillMajorType() {

		ArrayList<Major> arrayList = MajorDao.select();
		for (Major major : arrayList) {
			comboBoxMajor.addItem(major);
		}
	}

	private void fillMajorType(String mid) {

		ArrayList<Major> arrayList = MajorDao.select();
		for (Major major : arrayList) {
			if (mid.equals(major.getM_id())) {
				comboBoxMajor.addItem(major);
			}
		}
		for (Major major : arrayList) {
			if (!mid.equals(major.getM_id())) {
				comboBoxMajor.addItem(major);
			}
		}
	}

	/**
	 * 初始化下拉框
	 */
	private void fillClassType(Major major) {
		comboBoxClass.addItem("请选择班级");
		if (comboBoxMajor.getSelectedItem() instanceof Major) {
			ArrayList<Classinformation> arrayList = ClassinformationDao.select();
			for (Classinformation classinformation : arrayList) {
				if (classinformation.getM_id().equals(major.getM_id())) {
					comboBoxClass.addItem(classinformation);
				}
			}
		}
	}

	private void fillClassType(String classID) {
		Classinformation className = ClassinformationDao.select(classID);
		comboBoxClass.addItem(className);
		if (comboBoxMajor.getSelectedItem() instanceof Major) {
			ArrayList<Classinformation> arrayList = ClassinformationDao.select();
			Major major = (Major) comboBoxMajor.getSelectedItem();
			for (Classinformation classinformation : arrayList) {
				if (classinformation.getM_id().equals(major.getM_id())) {
					if (!classinformation.getCla_name().equals(className.getCla_name())) {
						comboBoxClass.addItem(classinformation);
					}
				}
			}
		}
	}
}
